// forcepil.txt
// Gives force to lightning pillars.
//Cell 0 - severity.
//Cell 1, 2 - A SDF.
beginterrainscript;
variables;
int disarmed = 0;
    int pause;
    int orig_mess;
    int mess;
    int rx, ry;
    int targ_num;
    int wait = 0;
body;
beginstate INIT_STATE;
    if ((get_memory_cell(1) > 0) || (get_memory_cell(2) > 0))
    {
        if (get_flag(get_memory_cell(1), get_memory_cell(2)) == 1)
            disarmed = 1;
    }
    if (get_memory_cell(0) == 0)
        set_terrain_memory_cell(my_number(), 0, 5);
    set_script_mode(3);
break;
beginstate 2;
      if (pause >= 0)
      {
          pause = pause - 1;   
          end();
      }
      if (disarmed == 1)
          end();
      orig_mess = my_current_message();
      mess = orig_mess;
      while (mess >= 99)
          mess = mess - 100;
      targ_num = orig_mess;
      if ((orig_mess != -1) && (wait == 0))
      {
          ry = mess;
          mess = orig_mess;
          rx = (mess - ry) / 100;
          wait = 1;
          broadcast_terrain_message(10, -11);
          end();
      }
      if ((orig_mess != -1) && (wait == 1))
      {
          targ_num = targ_num / 100;
          give_ter_script_message(targ_num, get_memory_cell(0));
          set_terrain(rx, ry, 453);
          set_terrain(my_loc_x(), my_loc_y(), 454);
          force_instant_terrain_redraw();
          put_jagged_zap(my_loc_x(), my_loc_y(), rx, ry, 6);
          run_animation_sound(62);
          pause = 5;
          wait = 0;
          orig_mess = 0;
      }
break;
beginstate SEARCH_STATE;
      if (get_flag(111, 24) != 0)
      {
	  set_terrain(my_loc_x(), my_loc_y(), 454);
	  force_instant_terrain_redraw();
	  put_effect_on_space(my_loc_x(), my_loc_y(), 10, 20, 0);
	  run_animation_sound(163);
	  if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0))
		  set_flag(get_memory_cell(1), get_memory_cell(2), 1);
	  disarmed = 1;
      }
break;